'use strict';
const db = uniCloud.database();
const memoCollection = db.collection('memo');

exports.main = async (event, context) => {
  try {
    // 从 event 中获取备忘录标题和时间信息
    const { title, time } = event;
    // 向 memo 集合插入新文档
    const res = await memoCollection.add({
      title,
      time
    });
    return {
      code: 200,
      message: '新增备忘录成功',
      data: res
    };
  } catch (error) {
    return {
      code: 500,
      message: '新增备忘录失败',
      error: error.message
    };
  }
};